<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
    var arr = [];
    for (var i = 0; i < 2; i++) {
        arr[i] = function() {
            console.log(i);
        }
    }    
    arr[0]();  // 2
    arr[1]();  // 2
    // 关键点在于变量 i 是全局的，函数执行时输出的都是全局作用域下的值
    </script>
</body>
</html>